package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入书名：");
        String name = scanner.nextLine();

        System.out.println("请输入作者：");
        String author = scanner.nextLine();

        System.out.println("请输入类型：");
        String type = scanner.nextLine();

        System.out.println("请输入价格：");
        int price = scanner.nextInt();

        Book book = new Book(name,author,price,type);


        int currentSize = bookList.books.usedSize;
        int count = bookList.books.elem.length;
        if (currentSize==count){
            System.out.println("书架已经满了！！");
            return;
        }
        for (int i = 0; i < currentSize; i++) {
            Book book1 = (Book)bookList.books.get(i);
            if (book.getName().equals(book1.getName())){
                System.out.println("已经有这本图书了！！");
                return;
            }
        }

        bookList.books.add(book);
        System.out.println("增加成功！！");
        return;
    }
}
